﻿namespace zyn_hy_login
{
    using System;
    using System.Data;

    public class Z8_tree
    {
        private DB_conn conn;
        private string connId;
        private int id;
        private int id2;
        private int id3;
        private string img;
        private string info;
        private string name;
        private string num;
        private string sign;
        private string tableName;
        private int type_id;
        private string url;
        private string x50;
        private string x51;
        private string x52;
        private string x53;
        private string x54;
        private string x55;
        private string x56;
        private string x57;
        private string x58;
        private string x59;
        private string x60;
        private string x61;
        private string x62;
        private string x63;
        private string x64;
        private string zt;

        public Z8_tree()
        {
        }

        public Z8_tree(string strconnId)
        {
            this.connId = strconnId;
            this.conn = new DB_conn(strconnId);
            this.tableName = this.conn.DbTable;
        }

        public Z8_tree(string strId, string strconnId)
        {
            this.connId = strconnId;
            this.conn = new DB_conn(strconnId);
            this.tableName = this.conn.DbTable;
            string strSql = " select * from " + this.tableName + " where type_id<>1 and id = " + strId;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            this.id = (int) row["id"];
            this.id2 = (int) row["id2"];
            this.id3 = (int) row["id3"];
            this.name = row["name"].ToString().Trim();
            this.num = row["num"].ToString().Trim();
            this.info = row["info"].ToString().Trim();
            this.zt = row["zt"].ToString().Trim();
            this.img = row["img"].ToString().Trim();
            this.url = row["url"].ToString().Trim();
            this.sign = row["sign"].ToString().Trim();
            this.type_id = (int) row["type_id"];
            this.x50 = row["x50"].ToString().Trim();
            this.x51 = row["x51"].ToString().Trim();
            this.x52 = row["x52"].ToString().Trim();
            this.x53 = row["x53"].ToString().Trim();
            this.x54 = row["x54"].ToString().Trim();
            this.x55 = row["x55"].ToString().Trim();
            this.x56 = row["x56"].ToString().Trim();
            this.x57 = row["x57"].ToString().Trim();
            this.x58 = row["x58"].ToString().Trim();
            this.x59 = row["x59"].ToString().Trim();
            this.x60 = row["x60"].ToString().Trim();
            this.x61 = row["x61"].ToString().Trim();
            this.x62 = row["x62"].ToString().Trim();
            this.x63 = row["x63"].ToString().Trim();
            this.x64 = row["x64"].ToString().Trim();
        }

        public Z8_tree(string strId, string strId2, string strconnId)
        {
            this.connId = strconnId;
            this.conn = new DB_conn(strconnId);
            this.tableName = this.conn.DbTable;
            string strSql = " select * from " + this.tableName + " where id = " + strId + " and id2=" + strId2;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            this.id = (int) row["id"];
            this.id2 = (int) row["id2"];
            this.id3 = (int) row["id3"];
            this.name = row["name"].ToString().Trim();
            this.num = row["num"].ToString().Trim();
            this.info = row["info"].ToString().Trim();
            this.zt = row["zt"].ToString().Trim();
            this.img = row["img"].ToString().Trim();
            this.url = row["url"].ToString().Trim();
            this.sign = row["sign"].ToString().Trim();
            this.type_id = (int) row["type_id"];
            this.x50 = row["x50"].ToString().Trim();
            this.x51 = row["x51"].ToString().Trim();
            this.x52 = row["x52"].ToString().Trim();
            this.x53 = row["x53"].ToString().Trim();
            this.x54 = row["x54"].ToString().Trim();
            this.x55 = row["x55"].ToString().Trim();
            this.x56 = row["x56"].ToString().Trim();
            this.x57 = row["x57"].ToString().Trim();
            this.x58 = row["x58"].ToString().Trim();
            this.x59 = row["x59"].ToString().Trim();
            this.x60 = row["x60"].ToString().Trim();
            this.x61 = row["x61"].ToString().Trim();
            this.x62 = row["x62"].ToString().Trim();
            this.x63 = row["x63"].ToString().Trim();
            this.x64 = row["x64"].ToString().Trim();
        }

        public int DelData(string strid)
        {
            string strSql = ("delete " + this.conn.DbTable + " where id = ") + " '" + strid + "'";
            try
            {
                this.conn.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public int getChildCount(string strId, string strId3, string usId3)
        {
            int num = 0;
            if (this.sign == "folder")
            {
                string strSql = " select id from " + this.conn.DbTable + " where id2 = " + strId + " and zt<>'0' ";
                num = this.conn.excuteSqlCount(strSql);
                if (usId3 != strId3)
                {
                    DB_conn _conn = new DB_conn(strId3);
                    string text2 = " select id from " + _conn.DbTable + " where id2 = " + strId + " and zt<>'0' ";
                    num += _conn.excuteSqlCount(text2);
                }
            }
            return num;
        }

        public string getMaxId(string strsign)
        {
            int num;
            string strSql = "";
            switch (strsign)
            {
                case "u":
                    strSql = " select max(id) as mid from " + this.conn.DbTable + " where id<59999 and id>=20000 ";
                    break;

                case "r":
                    strSql = " select max(id) as mid from " + this.conn.DbTable + " where id<69999 and id>=60000 ";
                    break;

                case "p":
                    strSql = " select max(id) as mid from " + this.conn.DbTable + " where id<99999 and id>=80000 ";
                    break;

                case "f":
                    strSql = " select max(id) as mid from " + this.conn.DbTable + " where id<199999 and id>=100000 ";
                    break;

                default:
                    strSql = " select max(id) as mid from " + this.conn.DbTable + " where  id>=200000 ";
                    break;
            }
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            string s = "";
            if (!row.IsNull(0))
            {
                s = row["mid"].ToString().Trim();
            }
            else
            {
                switch (strsign)
                {
                    case "u":
                        s = "19999";
                        goto Label_01A4;

                    case "r":
                        s = "59999";
                        goto Label_01A4;

                    case "p":
                        s = "79999";
                        goto Label_01A4;

                    case "f":
                        s = "99999";
                        goto Label_01A4;
                }
                s = "199999";
            }
        Label_01A4:
            num = int.Parse(s) + 1;
            return num.ToString();
        }

        public string getName(string strId)
        {
            string strSql = " select name from " + this.conn.DbTable + " where id = " + strId;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            return row["name"].ToString().Trim();
        }

        public int getNameCount(string pid, string cname, string zt)
        {
            string strSql = " select id from " + this.conn.DbTable + " where name='" + cname + "'and zt='" + zt + "' and id2=" + pid;
            return this.conn.excuteSqlCount(strSql);
        }

        public string getNewId(string strpid)
        {
            int num = int.Parse(strpid);
            if ((0x4e20 <= num) && (num < 0xea5f))
            {
                return this.getMaxId("u");
            }
            if ((0xea60 <= num) && (num < 0x1116f))
            {
                return this.getMaxId("r");
            }
            if ((0x13880 <= num) && (num < 0x1869f))
            {
                return this.getMaxId("p");
            }
            if ((0x186a0 <= num) && (num < 0x30d3f))
            {
                return this.getMaxId("f");
            }
            return this.getMaxId("5");
        }

        public string getParentId(string strId)
        {
            string strSql = " select id2 from " + this.conn.DbTable + " where id = " + strId;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            return row["id2"].ToString().Trim();
        }

        public string getProUrl()
        {
            DataRow row = DBCommon.getDataBySql(" select url from z8 where sign='pro' and id = " + this.type_id).Tables[0].Rows[0];
            return row["url"].ToString().Trim();
        }

        public string getSign(string strId)
        {
            string strSql = " select sign from " + this.conn.DbTable + " where id = " + strId;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            return row["sign"].ToString().Trim();
        }

        public int InsertData()
        {
            string strSql = (((((((((((((((((((((((((("insert into " + this.conn.DbTable + "(id,id2,id3,name,num,info,zt,img,url,sign,type_id,x50,x51,x52,x53,x54,x55,x56,x57,x58,x59,x60,x61,x62,x63,x64) values( ") + " " + this.id.ToString() + ",") + " " + this.id2.ToString() + ",") + " " + this.id3.ToString() + ",") + " '" + this.name + "',") + " '" + this.num + "',") + " '" + this.info + "',") + " '" + this.zt + "',") + " '" + this.img + "',") + " '" + this.url + "',") + " '" + this.sign + "',") + " " + this.type_id.ToString() + ",") + " '" + this.x50 + "',") + " '" + this.x51 + "',") + " '" + this.x52 + "',") + " '" + this.x53 + "',") + " '" + this.x54 + "',") + " '" + this.x55 + "',") + " '" + this.x56 + "',") + " '" + this.x57 + "',") + " '" + this.x58 + "',") + " '" + this.x59 + "',") + " '" + this.x60 + "',") + " '" + this.x61 + "',") + " '" + this.x62 + "',") + " '" + this.x63 + "',") + " '" + this.x64 + "' )";
            try
            {
                this.conn.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public void Set_date(string strId)
        {
            string strSql = " select * from " + this.conn.DbTable + " where id = " + strId;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            this.id = (int) row["id"];
            this.id2 = (int) row["id2"];
            this.id3 = (int) row["id3"];
            this.name = row["name"].ToString().Trim();
            this.num = row["num"].ToString().Trim();
            this.info = row["info"].ToString().Trim();
            this.zt = row["zt"].ToString().Trim();
            this.img = row["img"].ToString().Trim();
            this.url = row["url"].ToString().Trim();
            this.sign = row["sign"].ToString().Trim();
            this.type_id = (int) row["type_id"];
            this.x50 = row["x50"].ToString().Trim();
            this.x51 = row["x51"].ToString().Trim();
            this.x52 = row["x52"].ToString().Trim();
            this.x53 = row["x53"].ToString().Trim();
            this.x54 = row["x54"].ToString().Trim();
            this.x55 = row["x55"].ToString().Trim();
            this.x56 = row["x56"].ToString().Trim();
            this.x57 = row["x57"].ToString().Trim();
            this.x58 = row["x58"].ToString().Trim();
            this.x59 = row["x59"].ToString().Trim();
            this.x60 = row["x60"].ToString().Trim();
            this.x61 = row["x61"].ToString().Trim();
            this.x62 = row["x62"].ToString().Trim();
            this.x63 = row["x63"].ToString().Trim();
            this.x64 = row["x64"].ToString().Trim();
        }

        public void Set_date(string strId, string strId2)
        {
            string strSql = " select * from " + this.conn.DbTable + " where id = " + strId + " and id2=" + strId2;
            DataRow row = this.conn.getDataBySql(strSql).Tables[0].Rows[0];
            this.id = (int) row["id"];
            this.id2 = (int) row["id2"];
            this.id3 = (int) row["id3"];
            this.name = row["name"].ToString().Trim();
            this.num = row["num"].ToString().Trim();
            this.info = row["info"].ToString().Trim();
            this.zt = row["zt"].ToString().Trim();
            this.img = row["img"].ToString().Trim();
            this.url = row["url"].ToString().Trim();
            this.sign = row["sign"].ToString().Trim();
            this.type_id = (int) row["type_id"];
            this.x50 = row["x50"].ToString().Trim();
            this.x51 = row["x51"].ToString().Trim();
            this.x52 = row["x52"].ToString().Trim();
            this.x53 = row["x53"].ToString().Trim();
            this.x54 = row["x54"].ToString().Trim();
            this.x55 = row["x55"].ToString().Trim();
            this.x56 = row["x56"].ToString().Trim();
            this.x57 = row["x57"].ToString().Trim();
            this.x58 = row["x58"].ToString().Trim();
            this.x59 = row["x59"].ToString().Trim();
            this.x60 = row["x60"].ToString().Trim();
            this.x61 = row["x61"].ToString().Trim();
            this.x62 = row["x62"].ToString().Trim();
            this.x63 = row["x63"].ToString().Trim();
            this.x64 = row["x64"].ToString().Trim();
        }

        public int UpdateData()
        {
            object obj2 = (((((((((((((((((((((((((" update " + this.conn.DbTable + " set ") + "id2 = " + this.id2.ToString() + ",") + "id3 = " + this.id3.ToString() + ",") + "name = '" + this.name + "',") + "num = '" + this.num + "',") + "info = '" + this.info + "',") + "zt = '" + this.zt + "',") + "img = '" + this.img + "',") + "url = '" + this.url + "',") + "sign = '" + this.sign + "',") + "type_id= " + this.type_id.ToString() + ",") + "x50= '" + this.x50 + "',") + "x51= '" + this.x51 + "',") + "x52= '" + this.x52 + "',") + "x53= '" + this.x53 + "',") + "x54= '" + this.x54 + "',") + "x55= '" + this.x55 + "',") + "x56= '" + this.x56 + "',") + "x57= '" + this.x57 + "',") + "x58= '" + this.x58 + "',") + "x59= '" + this.x59 + "',") + "x60= '" + this.x60 + "',") + "x61= '" + this.x61 + "',") + "x62= '" + this.x62 + "',") + "x63= '" + this.x63 + "',") + "x64= '" + this.x64 + "' ";
            string strSql = string.Concat(new object[] { obj2, "where id = ", this.id, "" });
            try
            {
                this.conn.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public int UpdateDatax52()
        {
            object obj2 = (" update " + this.conn.DbTable + " set ") + "x52= '" + this.x52 + "'";
            string strSql = string.Concat(new object[] { obj2, "where id = ", this.id, "" });
            try
            {
                this.conn.excuteSql(strSql);
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public DB_conn Conn
        {
            get
            {
                return this.conn;
            }
            set
            {
                this.conn = value;
            }
        }

        public string ConnId
        {
            get
            {
                return this.connId;
            }
            set
            {
                this.connId = value;
            }
        }

        public int Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        public int Id2
        {
            get
            {
                return this.id2;
            }
            set
            {
                this.id2 = value;
            }
        }

        public int Id3
        {
            get
            {
                return this.id3;
            }
            set
            {
                this.id3 = value;
            }
        }

        public string Img
        {
            get
            {
                return this.img;
            }
            set
            {
                this.img = value;
            }
        }

        public string Info
        {
            get
            {
                return this.info;
            }
            set
            {
                this.info = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        public string Num
        {
            get
            {
                return this.num;
            }
            set
            {
                this.num = value;
            }
        }

        public string Sign
        {
            get
            {
                return this.sign;
            }
            set
            {
                this.sign = value;
            }
        }

        public string TableName
        {
            get
            {
                return this.tableName;
            }
            set
            {
                this.tableName = value;
            }
        }

        public int Type_id
        {
            get
            {
                return this.type_id;
            }
            set
            {
                this.type_id = value;
            }
        }

        public string Url
        {
            get
            {
                return this.url;
            }
            set
            {
                this.url = value;
            }
        }

        public string X50
        {
            get
            {
                return this.x50;
            }
            set
            {
                this.x50 = value;
            }
        }

        public string X51
        {
            get
            {
                return this.x51;
            }
            set
            {
                this.x51 = value;
            }
        }

        public string X52
        {
            get
            {
                return this.x52;
            }
            set
            {
                this.x52 = value;
            }
        }

        public string X53
        {
            get
            {
                return this.x53;
            }
            set
            {
                this.x53 = value;
            }
        }

        public string X54
        {
            get
            {
                return this.x54;
            }
            set
            {
                this.x54 = value;
            }
        }

        public string X55
        {
            get
            {
                return this.x55;
            }
            set
            {
                this.x55 = value;
            }
        }

        public string X56
        {
            get
            {
                return this.x56;
            }
            set
            {
                this.x56 = value;
            }
        }

        public string X57
        {
            get
            {
                return this.x57;
            }
            set
            {
                this.x57 = value;
            }
        }

        public string X58
        {
            get
            {
                return this.x58;
            }
            set
            {
                this.x58 = value;
            }
        }

        public string X59
        {
            get
            {
                return this.x59;
            }
            set
            {
                this.x59 = value;
            }
        }

        public string X60
        {
            get
            {
                return this.x60;
            }
            set
            {
                this.x60 = value;
            }
        }

        public string X61
        {
            get
            {
                return this.x61;
            }
            set
            {
                this.x61 = value;
            }
        }

        public string X62
        {
            get
            {
                return this.x62;
            }
            set
            {
                this.x62 = value;
            }
        }

        public string X63
        {
            get
            {
                return this.x63;
            }
            set
            {
                this.x63 = value;
            }
        }

        public string X64
        {
            get
            {
                return this.x64;
            }
            set
            {
                this.x64 = value;
            }
        }

        public string Zt
        {
            get
            {
                return this.zt;
            }
            set
            {
                this.zt = value;
            }
        }
    }
}

